package lan.core.io

import java.util.concurrent._

final class IOQueue {

  private val _queue = new ConcurrentLinkedQueue[TransferOperation]
  
  def queue(op: TransferOperation) = {
    if(!op.isDone) {
      _queue.add(op)
    }
  }
  
  def transferBit(buffer: Array[Byte]) = {
    val op = _queue.poll
    if(op != null) {
      queue(op.transfer(buffer))
      true
    } else {
      false
    }
  }
  
  def size = _queue.size
  
}
